/**
 * 一些静态方法
 */
package cn.antia.cwin.window;

import java.util.*;

import cn.antia.cwin.Cele;

/**
 * @author sunkei
 * @date Jan 3, 2008
 * @time 11:14:20 PM
 */
public class Window {
	/**
	 * 取得一个ElementComsat列表中的所有有创建值的Element
	 * @param elements elements
	 * @return List<Cele>
	 */
	public static List<Cele> getCreateValueFields(List<Cele> elements){
		List<Cele> list = new ArrayList<Cele>();
		if(elements != null && elements.size() > 0){
            for (Cele element : elements) {
                if (element.getField().getDefault() != null) {
                    list.add(element);
                }
            }
		}
		return list;
	}
	/**
	 * 取得一个ElementComsat列表中的所有有修改值的Element
	 * @param elements elements
	 * @return List<Cele>
	 */
	public static List<Cele> getModifyValueFields(List<Cele> elements){
		List<Cele> list = new ArrayList<Cele>();
		if(elements != null && elements.size() > 0){
            for (Cele element : elements) {
                if (element.getField().getModifyValue() != null) {
                    list.add(element);
                }
            }
		}
		return list;
	}
	/**
     * 如果没有字段，则加上
     * @param eles eles
     * @param addFields addFields
     * @return Map<Cele,Object>
     */
    public static Map<Cele,Object> addIfNotExist(Map<Cele,Object> eles,List<Cele> addFields){
    	if(eles == null){
    		eles = new HashMap<Cele,Object>();
    	}
    	if(addFields != null && addFields.size() > 0){
    		String addField,tempField;
    		boolean isExist;
            for (Cele addField1 : addFields) {
                addField = addField1.getField().getFieldName();
                isExist = false;
                for (Cele ac : eles.keySet()) {
                    tempField = ac.getField().getFieldName();
                    if (addField.equals(tempField)) {
                        isExist = true;
                        break;
                    }
                }
                if (!isExist) {
                    eles.put(addField1,null);
                }
            }
    	}
    	return eles;
    }
}
